package com.nineclock.system.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.nineclock.system.service.SysCompanyUserService;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@Slf4j
public class MemberListener extends AnalysisEventListener<ExcelMember> {

    SysCompanyUserService companyUserService;
    //通过构造方法 传参 企业用户service对象
    public MemberListener(SysCompanyUserService companyUserService){
        this.companyUserService = companyUserService;
    }

    List<ExcelMember> members = new ArrayList<>();

    //每读取一行执行一次
    @Override
    public void invoke(ExcelMember data, AnalysisContext context) {
        members.add(data);
    }


    //读取完成后 执行一次
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        log.info("members:" + members);
        companyUserService.handlerData(members);
    }
}
